﻿using System;
using System.Collections.Generic;
using System.Data;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Xml.Linq;
using Models;

namespace DAL
{
    
    public class ChulianSeriver
    {
        //登录
        public static DataTable SelectAdmin(adminModel admin)
        {
            string sql = string.Format("select * from cl_admin where adminName='{0}' and adminPass='{1}'", admin.AdminName, admin.AdminPass);
            return DBHelper.Select(sql);
        }
        //获取网站设置
        public static DataTable selectWeb()
        {
            string sql = string.Format("select * from cl_web");
            return DBHelper.Select(sql);
        }
        //更新网站设置
        public static bool updateWeb(WebModels web)
        {
            string sql = string.Format("update cl_web set name='{0}',qq='{1}',qun='{2}',ms='{3}',gjc='{4}',gg='{5}',lg='{6}' where id=6 ",
                web.Name, web.QQ, web.Qun,web.MS,web.GJC,web.GG,web.LG);
            return DBHelper.Zsg(sql);
        }
        //更新接口
        public static bool updateApi(WebModels web)
        {
            string sql = string.Format("update cl_web set oneapi='{0}',twoapi='{1}',thirapi='{2}',fromapi='{3}' where id=6", web.OneApi, web.TwoApi, web.ThirdApi, web.FroApi);
            return DBHelper.Zsg(sql);
        }
        //查询所有用户
        public static DataTable selectUser()
        {
            string sql = string.Format("select * from cl_user");
            return DBHelper.Select(sql);
        }
        //查询id用户
        public static DataTable selectUser(int id)
        {
            string sql = string.Format("select * from cl_user where id="+id);
            return DBHelper.Select(sql);
        }
        //删除用户
        public static bool DeleteUser(int id)
        {
            string sql = string.Format("delete from cl_user where id=" + id);
            return DBHelper.Zsg(sql);
        }
        //查询用户（模糊查询）
        public static DataTable selectName(userModels userModels)
        {
            string sql = string.Format("select * from cl_user where userName like '%{0}%'" , userModels.userName);
            return DBHelper.Select (sql);
        }
        //添加用户
        public static bool Insert(userModels user)
        {
            string sql = string.Format("insert into cl_user (userName,email,qq,password,intime,status)values('{0}','{1}',{2},'{3}','{4}',{5})",user.userName,user.Email,user.QQ,user.Password,user.Intime,user.Status);
            return DBHelper.Zsg (sql);
        }
        //更新用户
        public static bool updateUser(userModels user)
        {
            string sql = string.Format("update cl_user set userName='{0}',email='{1}',qq={2},password='{3}',intime='{4}',status={5} where id={6}",user.userName,user.Email,user.QQ,user.Password,user.Intime,user.Status,user.Id);
            return DBHelper.Zsg (sql);
        }
    }
}
